package com.zhoutao.blog.seven.pages;


import com.zhoutao.blog.seven.service.CategoryService;
import com.zhoutao.blog.seven.service.MenuService;
import com.zhoutao.blog.seven.service.SettingService;
import com.zhoutao.blog.seven.service.TagService;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;

import javax.servlet.http.HttpSession;

public abstract class AbstractPageController {


    @Autowired
    private MenuService menuService;

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private TagService tagService;

    @Autowired
    private HttpSession session;

    @Autowired
    private SettingService settingService;


    /**
     * 封装基本信息
     *
     * @param model
     */
    @SneakyThrows
    public void packageBaseInfo(Model model) {
        model.addAttribute("login", session.getAttribute("userId") != null);
        model.addAttribute("menus", menuService.all());
        model.addAttribute("blogCategory", categoryService.list());
        model.addAttribute("tags", tagService.list());
        model.addAttribute("info", settingService.findConfigByKey());
    }

    /**
     * 封装基本信息
     *
     * @param model
     */
    @SneakyThrows
    public void packageAdminInfo(Model model) {

        model.addAttribute("menus", menuService.all());

        model.addAttribute("blogCategory", categoryService.list());

        model.addAttribute("tags", tagService.list());
    }
}
